package com.aischool.webapp.teacher;

import com.aischool.params.AiArticleParams;
import com.aischool.routes.RouteMapping;
import com.aischool.service.AiAppArticleService;
import com.aischool.service.AiArticleService;
import com.aischool.service.AiArticlecatService;
import com.aischool.utils.AppUtil;
import com.aischool.utils.JsonCodeEnum;
import com.aischool.utils.JsonResult;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;

@RouteMapping(url = "/front/teacher/article")
public class AiArticleController extends BaseTeacherController {

	@Inject
	AiArticleService aiArticleService;
	@Inject
	AiArticlecatService aiArticlecatService;
	@Inject
	AiAppArticleService aiAppArticleService;
	
	public void getPage() {
		// 结果类
		JsonResult jr = new JsonResult();
		// 参数类
		AiArticleParams params = new AiArticleParams();
		
		// 获取参数
		int org_id = this.getAttrForInt("login_org_id");
		
		params.setPageNo(getParaToInt("pageNo", 1));
		params.setPageSize(getParaToInt("pageSize", AppUtil.Default_PageSize));
		
		params.setState(1);
		params.setUseState(getParaToInt("usestate", -1));
		
		params.setOrgId(org_id);
		params.setCatId(getInt("catid",0));
		params.setTypeId(getInt("typeid",0));
		
		// 获取分页
		Object pageData = aiArticleService.getPage(params);
		
		jr.setDicKV("pageData", pageData);
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	public void detaile() {
		int id = getInt("id", 0);
		Record rd = aiArticleService.getOne(id);
		this.setAttr("article_rd", rd);
		render(view_path + "/article_detaile.html");
	}
	
	
	public void getArticleCat() {
		// 结果类
		JsonResult jr = new JsonResult();
		
		int org_id = this.getAttrForInt("login_org_id");
		int type_id = getInt("type_id", 0);
		
		Object obj = aiArticlecatService.getOrgCat(org_id, type_id, 1);
		if (obj != null) { jr.setDicKV("listcat", obj); }
		
		jr.setEnum(JsonCodeEnum.Success);
		renderJson(jr.Dic);
	}
	
	
}
